package com.example.chinawenddingexpo.service;

import com.example.chinawenddingexpo.model.Exhibitor;
import com.example.chinawenddingexpo.repository.ExhibitorRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class ExhibitorService {
    
    @Autowired
    private ExhibitorRepository exhibitorRepository;
    
    public List<Exhibitor> getAllActiveExhibitors() {
        return exhibitorRepository.findByActiveTrueOrderByPriorityDesc();
    }
    
    public List<Exhibitor> getExhibitorsByType(Exhibitor.ExhibitorType type) {
        return exhibitorRepository.findByTypeAndActiveTrueOrderByPriorityDesc(type);
    }
    
    public List<Exhibitor> searchExhibitorsByName(String companyName) {
        return exhibitorRepository.findByCompanyNameContainingIgnoreCaseAndActiveTrue(companyName);
    }
    
    public List<Exhibitor> getDiscountExhibitorsByType(Exhibitor.ExhibitorType type) {
        return exhibitorRepository.findDiscountExhibitorsByType(type);
    }
    
    public Exhibitor getExhibitorById(Long id) {
        Optional<Exhibitor> exhibitor = exhibitorRepository.findById(id);
        return exhibitor.orElse(null);
    }
    
    public Exhibitor saveExhibitor(Exhibitor exhibitor) {
        return exhibitorRepository.save(exhibitor);
    }
    
    public void deleteExhibitor(Long id) {
        exhibitorRepository.deleteById(id);
    }
}